﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace DiscoveryLogic.Workflows.Monitor.Avalon.PatientHelper
{
    public class SearchXPSItemCollection : ObservableCollection<SearchXPSItem>
    {
        public event EventHandler SearchXPSItemCostChanged;

        public new void Add(SearchXPSItem item)
        {
            if (item != null)
            {
                item.PropertyChanged += new PropertyChangedEventHandler(SearchXPSItemPropertyChanged);
            }
            base.Add(item);

            RaiseSearchXPSItemCostChanged(this, new EventArgs());
        }

        public new void Remove(SearchXPSItem item)
        {
            base.Remove(item);

            RaiseSearchXPSItemCostChanged(this, new EventArgs());
        }

        private void SearchXPSItemPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Cost")
            {
                RaiseSearchXPSItemCostChanged(this, new EventArgs());
            }
        }

        void RaiseSearchXPSItemCostChanged(object sender, EventArgs args)
        {
            if (SearchXPSItemCostChanged != null)
            {
                SearchXPSItemCostChanged(sender, args);
            }
        }
    }
}
